<?php
    include("custom/include/Date.php");
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  Class ProcessList{
        function contactScoreLightLightAuto(&$bean,$event,$arguments){
            global $db, $app_list_strings;
            
            $sql = "SELECT diemxephang, loaikhachhang,date_modified FROM contacts WHERE id='{$bean->id}' AND deleted = 0";
            $result = $db->query($sql); 
            $row = $db->fetchByAssoc($result);
            $date = date('Y-m-d',strtotime($row['date_modified']));
            $dateAcc =  strtotime($date);
            $dateNow = date("Y-m-d");
            $now = strtotime($dateNow);
            $clsDate = new Date();
            $dNum = $clsDate->dateDiff($now,$dateAcc);
            $img_src = "";
            $style = "";
            if($dNum['d']== $app_list_strings['config']['no_actives']){
                $img_src = "custom/themes/default/images/warning_icon.gif";
                 $style = "style='width:16px ;height:16px'";       
            }
            else{
                $img_src ="themes/Sugar5/images/Accounts.gif'";
                $style = "style='display:none; width:0px ;height:0px'";
            }
            $color = '';
            if($row['diemxephang'] >= $app_list_strings['config']['vip_income_limit'] && $row['loaikhachhang'] =='Nomal'){
                $color = "cusuptovip";
                        
            }else if($row['diemxephang'] < $app_list_strings['config']['vip_income_limit'] && $row['loaikhachhang'] =='VIP'){
                    $color = "cusdowntonormal";
                         
            }
            //if($img_src != "" && $style != "" && $color != ""){
               $img = "<img src='{$img_src}' {$style} onload='this.parentNode.parentNode.className = \"".$color."\";'>";
               //$bean->code .= " ";
               $bean->code .= $img; 
            //}
            
            /*
            
            global $db, $app_list_strings;
            
            $sql = "SELECT diemxephang, loaikhachhang,date_modified FROM contacts WHERE id='{$bean->id}' AND deleted = 0";
            $result = $db->query($sql); 
            $row = $db->fetchByAssoc($result);
            $color =''; 
            if($bean->diemxephang >= 200 && $bean->loaikhachhang != 'VIP'){
                $color ='vip'; 
            } 
            if($bean->diemxephang < 200 && $bean->loaikhachhang == 'VIP'){
                $color ='nomal'; 
            }
            if($color != ''){
                $bean->loaikhachhang .= "<img style='display:none;' src='themes/Sugar5/images/help.gif' width='0' height='0'  onload='this.parentNode.parentNode.className = \"".$color."\";'> ";
            } */
            
        }
    }   
?>
